package de.zainodis.commons.utils;

public class StringUtils {

   public static final String NEW_LINE = "\n";
   public static final String EMPTY = "";
   public static final String COMMA = ",";
   public static final String DOT = ".";
   public static final String SLASH = "/";

   /**
    * @return the passed string, stripped of leading and trailing whitespace
    *         characters (including tabs etc.)
    */
   public static String trim(String toTrim) {

	 toTrim = toTrim.replaceAll("[^\\S ]", EMPTY);
	 toTrim = toTrim.trim();
	 return toTrim;
   }

   public static boolean equals(String left, String right) {

	 if (left == null) {
	    return right == null;
	 }
	 if (right == null) {
	    return left == null;
	 }

	 return left.equals(right);
   }

   public static String firstLetterToUppercase(String value) {
	 if (value == null || EMPTY.equals(value)) {
	    return value;
	 }

	 StringBuilder sb = new StringBuilder(value);
	 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
	 return sb.toString();
   }

   /**
    * 
    * @param value
    *           the value to check may be null as well in which case true would
    *           be returned.
    * @return true if the given value is null or an empty {@link String}; false
    *         otherwise.
    */
   public static boolean isEmpty(String value) {
	 if (value == null) {
	    return true;
	 }

	 return EMPTY.equals(value);

   }
}
